package com.mop.sg2.map;

import org.apache.mina.core.buffer.IoBuffer;

public class RoleInfoMsg {

	int level = 0;

	String roleName = null;

	String roleArmyName = null;

	short roleNation = 0;

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public String getRoleArmyName() {
		return roleArmyName;
	}

	public void setRoleArmyName(String roleArmyName) {
		this.roleArmyName = roleArmyName;
	}

	public short getRoleNation() {
		return roleNation;
	}

	public void setRoleNation(short roleNation) {
		this.roleNation = roleNation;
	}

	public IoBuffer write() {
		System.out.println("Send==========");
		IoBuffer buffer = IoBuffer.allocate(1024);
		//
		buffer.position(2);

		buffer.putShort((short) 3);

		// 写一个Int
		buffer.putInt(this.level);
		System.out.println("level:" + this.level);

		// 写一个String
		byte[] string_byte = this.roleName.getBytes();

		buffer.putShort((short) string_byte.length);

		buffer.put(string_byte);

		System.out.println("roleName:" + this.roleName);

		// 写一个String
		string_byte = this.roleArmyName.getBytes();

		buffer.putShort((short) string_byte.length);

		buffer.put(string_byte);

		System.out.println("roleArmyName:" + this.roleArmyName);

		// 写一个Short
		buffer.putShort(this.roleNation);

		System.out.println("roleNation:" + this.roleNation);

		//
		int length = buffer.position();

		buffer.position(0);
		buffer.putShort((short) (length - 2));

		buffer.position(length);
		buffer.flip();

		return buffer;
	}

}
